package sh.wnxy.wn38.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import sh.wnxy.wn38.entity.Cart;
import sh.wnxy.wn38.entity.Ticket;
import sh.wnxy.wn38.mapper.CartMapper;
import sh.wnxy.wn38.mapper.TicketMapper;
import sh.wnxy.wn38.service.ICartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wn38
 * @since 2021-07-13
 */
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements ICartService {


    private CartMapper cartMapper;

    @Autowired
    public void setCartMapper(CartMapper cartMapper) {
        this.cartMapper = cartMapper;
    }

    private TicketMapper ticketMapper;
    @Autowired
    public void setTicketMapper(TicketMapper ticketMapper) {
        this.ticketMapper = ticketMapper;
    }

    @Override
    public List<Cart> selectall(String id) {
        return cartMapper.selectall(id);
    }

    @Override
    public Ticket selectTicekt(Integer id) {
        return cartMapper.selectTicket(id);
    }

    @Override
    public String getSpotName(Integer ticketSpotId) {
        return cartMapper.getSpotName(ticketSpotId);
    }

    @Override
    public String selectPath(Integer ticketSpotid) {
        return cartMapper.selectPath(ticketSpotid);
    }

    @Override
    public boolean updateNumber(Integer index, Integer number) {
        boolean result=cartMapper.updateNumber(index,number);
        return result;
    }

    @Override
    public Ticket changeTicket(Integer index, LocalDate date) {
        Cart cart = cartMapper.selectById(index);
        Ticket ticket = cartMapper.selectTicket(cart.getCartTicketid());
        ticket.setTicketDate(date);
        QueryWrapper<Ticket> Ticket = new QueryWrapper<>(ticket);
        Ticket ticket1 = ticketMapper.selectOne(Ticket);
        if(ticket1==null){
            ticketMapper.insert(ticket);
        }
        return ticket;
    }
}
